package com.hr;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Transient;

import org.hibernate.annotations.Index;
import org.hibernate.annotations.Table;

import com.espirit.EntityMapping;
import com.espirit.common.VersionAware;
import com.espirit.eap.annotation.DomainModel;
import com.espirit.eap.manager.Department;
import com.espirit.eap.sa.Employee;
import com.espirit.eap.sa.EmployeeAware;
import com.espirit.eap.sa.User;
import com.espirit.finance.core.AcctTerm;
import com.espirit.finance.core.AcctTermCheckAware;
import com.googlecode.cswish.model.Saas;

@Entity
@DomainModel
@Table(indexes={
		@Index(name="idx_empdate", columnNames={"employee_id","realdate"} )},appliesTo = "hr_rewardfaultitem")
public class RewardFaultItem extends EntityMapping implements Serializable, EmployeeAware, VersionAware, AcctTermCheckAware, Saas{
	private static final long serialVersionUID = -4375401423058981810L;

	private Integer sid;
	public Integer getSid() {
		return sid;
	}

	public void setSid(Integer sid) {
		this.sid = sid;
	}
	
	@ManyToOne(fetch=FetchType.LAZY)
	public Employee getEmployee() {
		return employee;
	}
	public void setEmployee(Employee employee) {
		this.employee = employee;
	}

	@ManyToOne(fetch=FetchType.LAZY)
	public Department getDepartment() {
		return department;
	}
	public void setDepartment(Department department) {
		this.department = department;
	}

	public Date getCreatedOn() {
		return createdOn;
	}
	public void setCreatedOn(Date createdOn) {
		this.createdOn = createdOn;
	}

	public String getRemark() {
		return remark;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}

	public BigDecimal getAmount() {
		return amount;
	}
	public void setAmount(BigDecimal amount) {
		this.amount = amount;
	}

	public Date getRealDate() {
		return realDate;
	}
	public void setRealDate(Date realDate) {
		this.realDate = realDate;
	}

	@ManyToOne(fetch=FetchType.LAZY)
	public User getCreated() {
		return created;
	}
	public void setCreated(User created) {
		this.created = created;
	}
	
	@Transient
	public String getDeptIds() {
		return deptIds;
	}
	public void setDeptIds(String deptIds) {
		this.deptIds = deptIds;
	}
	
	@Override
	public boolean check(AcctTerm acctTerm) {
		if (acctTerm != null && acctTerm.getBeginDate() != null && this.realDate != null){
			return acctTerm.getBeginDate().compareTo(this.realDate) < 0;
		} else {
			return true;
		}
	}
	
	public BigDecimal getRewardAmount() {
		return rewardAmount;
	}
	public void setRewardAmount(BigDecimal rewardAmount) {
		this.rewardAmount = rewardAmount;
	}

	public BigDecimal getPunishAmount() {
		return punishAmount;
	}
	public void setPunishAmount(BigDecimal punishAmount) {
		this.punishAmount = punishAmount;
	}

	private BigDecimal amount;
	private Employee employee;
	private Department department;
	private String remark;
	private Date createdOn;
	private User created;
	private Date realDate;
	private String deptIds;
	
	private BigDecimal rewardAmount;
	private BigDecimal punishAmount;
	
}
